/* 产引入jsencrypt实现数据RSA加密 */
import JSEncrypt from 'jsencrypt' // 处理长文本数据时报错 jsencrypt.js Message too long for RSA
/* 产引入encryptlong实现数据RSA加密 */
import Encrypt from 'encryptlong' // encryptlong是基于jsencrypt扩展的长文本分段加解密功能。
import utils from "./utils"
import config from './config'
// 公钥key
const publicKey = config.RsaPublicKey;

// 私钥key
const privateKey = config.RsaPrivateKey;
// 加密随机字符
export default {
	encrypt(keyStr) {
		let encrypt = new JSEncrypt();
		encrypt.setPublicKey(publicKey);
		let encrypted = encrypt.encrypt(keyStr);
		console.log('加密后数据:%o', encrypted);
		return encrypted
	},
	decrypt(str) {
		//使用私钥解密
		let decrypt = new JSEncrypt();
		decrypt.setPrivateKey(privateKey);
		let uncrypted = decrypt.decrypt(str);
		console.log('解密后数据:%o', uncrypted); 
		return uncrypted;
	}
}
